package com.guigu.tms.aggregation.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.tms.aggregation.mapper.*;
import com.guigu.tms.commons.aggregation.entity.*;
import com.guigu.tms.aggregation.service.IDriverJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 司机作业单 服务实现类
 * </p>
 *
 * @author wj
 * @since 2022-10-21
 */
@Service
public class DriverJobServiceImpl extends ServiceImpl<DriverJobMapper, DriverJob> implements IDriverJobService {
@Autowired
        DriverJobMapper driverJobMapper;
        //司机姓名关联表
    @Autowired
        TruckDriverMapper truckDriverMapper;
    @Autowired
        //用户表
        AuthUserMapper authUserMapper;
    @Autowired
        //运输任务表
        TaskTransportMapper transportMapper;
    @Autowired
    CoreOrgMapper mapper;
    @Autowired
    TruckMapper truckMapper;
    @Override
    public PageInfo<DriverJob> DriverJobAll(String id,String name,Integer status,String taskTransportId,Integer num, Integer size) {
        PageHelper.startPage(num==null?1:num,size==null?5:size);
        List<DriverJob> driverJobs = driverJobMapper.DriverJobAll(id, name, status, taskTransportId);

        for (DriverJob driverJob : driverJobs) {
            //根据UserId查询司机姓名。
            String userId = driverJob.getUserId();
            AuthUser authUser = authUserMapper.selectById(userId);
            //取出司机姓名
            authUser.getName();
            driverJob.setName(authUser.getName());

            //查转运机构
            String startAgencyId = driverJob.getStartAgencyId();
            driverJob.setJgName(mapper.selectById(startAgencyId).getName());

            //查询车辆信息
            driverJob.setTruck(truckMapper.selectById(driverJob.getTruckId()));
        }
        return new PageInfo<DriverJob>(driverJobs);
    }
}
